<?php
/**
 * Created by PhpStorm.
 * User: Sixstar-Peter
 * Date: 2019/4/16
 * Time: 21:46
 */


$server = new  Swoole\Http\Server('0.0.0.0', 9800);
$server->set(
    ['worker_num' => 1]
);

include "Contexts.php";
//一个协程的数据被另外一个协程修改了
$server->on('request', function ($req, $response) {
    // $context=new Co\Context();
    //$context=Co::getContext();
    $key = $req->get['key'];
    //$context['name']=$key;
    if ($key == 'sleep') {
        Co::sleep(10); //模拟耗时操作,挂起了当前协程
    }
    var_dump(empty((array)Co::getContext())); //判断是否有值
    //var_dump($context);
    $response->end('协程id为' . Co::getcid());
});
$server->start();